package com.itheima.stock.controller;

import com.itheima.stock.domain.InnerMarketDomain;
import com.itheima.stock.domain.Stock4EvrDayDomain;
import com.itheima.stock.domain.Stock4MinuteDomain;
import com.itheima.stock.domain.StockUpdownDomain;
import com.itheima.stock.domain.Stock4OuterMarketDomain;
import com.itheima.stock.pojo.domain.StockBlockDomain;
import com.itheima.stock.pojo.vo.*;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 定义股票相关接口控制器
 */
@Api(value = "/api/quot", tags = {"}"})
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘最新的数据
     * @return
     */
    @ApiOperation(value = "获取国内大盘最新的数据", notes = "获取国内大盘最新的数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo(){
        return stockService.getInnerMarketInfo();
    }

    /**
     * 分页查询最新的股票交易数据
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "分页查询最新的股票交易数据", notes = "分页查询最新的股票交易数据", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockInfoByPage(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                                               @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockInfoByPage(page,pageSize);
    }

//    @GetMapping("stock/increase")
//    public R<PageResult<StockUpdownDomain>> getStockIncreaseByPage(){
//
//    }

    /**
     * 统计最新股票交易日内每分钟的涨跌停的股票数量
     * @return
     */
    @ApiOperation(value = "统计最新股票交易日内每分钟的涨跌停的股票数量", notes = "统计最新股票交易日内每分钟的涨跌停的股票数量", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String,List>> getStockUpDownCount(){
        return stockService.getStockUpDownCount();
    }

    /**
     * 导出指定页码的最新股票信息
     * @param page 当前页
     * @param pageSize 每页大小
     * @param response
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "导出指定页码的最新股票信息", notes = "导出指定页码的最新股票信息", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void getStockInfoByPage(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                   @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize,
                                   HttpServletResponse response){
        stockService.exportStockUpDownInfo(page,pageSize,response);
    }

    /**
     * 统计大盘T日和T-1日每分钟交易量的统计
     * @return
     */
    @ApiOperation(value = "统计大盘T日和T-1日每分钟交易量的统计", notes = "统计大盘T日和T-1日每分钟交易量的统计", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getComparedStockTradeAmt(){
        return stockService.getComparedStockTradeAmt();
    }

    /**
     * 统计最新交易时间点下股票（A股）在各个涨幅区间的数量
     * @return
     */
    @ApiOperation(value = "统计最新交易时间点下股票（A股）在各个涨幅区间的数量", notes = "统计最新交易时间点下股票（A股）在各个涨幅区间的数量", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> getIncreaseRangeInfo(){
        return stockService.getIncreaseRangeInfo();
    }

    /**
     * 获取指定股票T日的分时数据
     * @param stockCode 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "获取指定股票T日的分时数据", notes = "获取指定股票T日的分时数据", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenTimeSharing(stockCode);
    }

    /**
     * 统计指定股票的日K线数据
     * @param stockCode 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "统计指定股票的日K线数据", notes = "统计指定股票的日K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDkLine(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenDkLine(stockCode);
    }


    /**
     *需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
     * @return
     */
    @ApiOperation(value = "需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据", notes = "需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAllLimit();
    }

    /**
     * 外盘指数行情数据查询，根据时间和大盘点数降序排序取前4
     * @return
     */
    @ApiOperation(value = "外盘指数行情数据查询，根据时间和大盘点数降序排序取前4", notes = "外盘指数行情数据查询，根据时间和大盘点数降序排序取前4", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<Stock4OuterMarketDomain>> getStock4OuterInfo(){
        return stockService.getStock4OuterInfo();
    }

    /**
     * 模糊搜索，根据传入的股票代码模糊搜索股票数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "searchStr", value = "", required = true)
    })
    @ApiOperation(value = "模糊搜索，根据传入的股票代码模糊搜索股票数据", notes = "模糊搜索，根据传入的股票代码模糊搜索股票数据", httpMethod = "GET")
    @GetMapping("/stock/search")
    public R<List<StockSearchInfo>> getStockSearchInfo(@RequestParam(value = "searchStr",required = true) String code){
        return stockService.searchStock(code);
    }

    /**
     * 个股主营业务查询
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "个股主营业务查询", notes = "个股主营业务查询", httpMethod = "GET")
    @GetMapping("/stock/describe")
    public R<StockDescribeInfo> getStockRtDescribe(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockDescribe(code);
    }

    /**
     *  统计每周内的股票数据信息，信息包含：
     * 	股票ID、 一周内最高价、 一周内最低价 、周1开盘价、周5的收盘价、
     * 	整周均价、以及一周内最大交易日期（一般是周五所对应日期）
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "统计每周内的股票数据信息，信息包含： 	股票ID、 一周内最高价、 一周内最低价 、周1开盘价、周5的收盘价、 	整周均价、以及一周内最大交易日期（一般是周五所对应日期）", notes = "统计每周内的股票数据信息，信息包含： 	股票ID、 一周内最高价、 一周内最低价 、周1开盘价、周5的收盘价、 	整周均价、以及一周内最大交易日期（一般是周五所对应日期）", httpMethod = "GET")
    @GetMapping("/stock/screen/weekkline")
    public R<StockRtWeeklyInfo> getStockRtWeeklyInfo(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockRtWeeklyInfo(code);
    }

    /**
     * 	获取个股最新分时行情数据，主要包含：
     * 	开盘价、前收盘价、最新价、最高价、最低价、成交金额和成交量、交易时间信息;
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "获取个股最新分时行情数据，主要包含： 	开盘价、前收盘价、最新价、最高价、最低价、成交金额和成交量、交易时间信息;", notes = "获取个股最新分时行情数据，主要包含： 	开盘价、前收盘价、最新价、最高价、最低价、成交金额和成交量、交易时间信息;", httpMethod = "GET")
    @GetMapping("/stock/screen/second/detail")
    public R<StockRt> getStockRtInfo(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockRtRecentInfo(code);
    }

    /**
     * 个股交易流水行情数据查询--查询最新交易流水，按照交易时间降序取前10
     * @return
     */
    @GetMapping("/stock/screen/second")
    public R<List<StockRtScreen>> getStockRtScreenSecond(@RequestParam(value = "code",required = true) String code){
        return stockService.getStockRtScreenSecond(code);
    }

}
